﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Collections;

namespace Web
{
    public partial class tree : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string strDirlist = Server.MapPath("C#基类库大全2013-03-27-11-45");
                GetAllDirList(strDirlist, TreeView1.Nodes);
            }
        }

        private void GetAllDirList(string path, TreeNodeCollection nodes)
        {
            DirectoryInfo di = new DirectoryInfo(path);
            DirectoryInfo[] diA = di.GetDirectories();
            for (int i = 0; i < diA.Length; i++)
            {
                DirectoryInfo info = diA[i];
                TreeNode new_child = new TreeNode();
                new_child.Collapse();
                new_child.Value = info.FullName;
                new_child.Text = info.Name;
                nodes.Add(new_child);
                GetAllDirList(diA[i].FullName, new_child.ChildNodes);
            }
        }

        protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
        {
            Response.Write(TreeView1.SelectedValue);

            DirectoryInfo di = new DirectoryInfo(TreeView1.SelectedValue);
            foreach (var item in di.GetFiles())
            {
                list.InnerHtml += item.Name + "<br/>";
            }
        }
    }
}